from WoniuBoss.Login import LogIn
import requests


class StuManage:
    def __init__(self):
        self.base_url = 'http://192.168.7.252:8080'
        login = LogIn(self.base_url)
        self.s = login.login()

    def base_info_update(self):
        # 修改基本信息
        url = self.base_url + '/WoniuBoss2.5/student/saveNewInfo'
        data = {"stu.student_id": (None, "1275"), "stu.student_name": (None, "冷佩111")}
        r = self.s.post(url, files=data)
        print(r.text)
        print(r.request.body)  # 查看请求正文是否符合要求
        print(r.request.headers)  # 查看请求头部是否符合要求

    def photo_modify(self):
        # 基本信息修改头像
        url = self.base_url + '/WoniuBoss2.5/student/saveNewInfo'
        upload_file = {'img': ('photo.png', open('E:/Python/APITest/WoniuBoss/photo.jpg', 'rb'))}
        # 必须添加学生id, 名字,还有学号
        data = {"stu.student_id": "1274", "stu.student_name": "李劲昆", 'stu.student_no': 'WNCD201805037'}
        r = self.s.post(url, files=upload_file, data=data)
        # print(r.request.body)
        # print(r.encoding)
        print(r.text)

    def check_in_search(self):
        # 今日考勤数据根据姓名查询
        # 要点:使用讲师用户名登陆, 并确保讲师有排课记录
        url = self.base_url + '/WoniuBoss2.5/student/queryStuOfAtten'
        data = {'pageSize': '30', 'pageIndex': 'a.txt', 'stuName': '敬大彦'}
        headers = {'Content-Type': 'application/x-www-form-urlencoded'}
        r = self.s.post(url, data=data, headers=headers)
        print(r.json())

    def arrange_course(self):
        # 新增排课
        url = self.base_url + '/WoniuBoss2.5/student/saveCourse'
        data = {
            'arr': '[{"work_id":"WNCD005","classroom_id":"4","class_no":"WNCDC031","orientation":"公共","course_id":"3","teacher_status":"正常"},{"work_id":"WNCD056","classroom_id":"全部","class_no":"全部","orientation":"全部","course_id":"全部","teacher_status":"实训"},{"work_id":"WNCD024","classroom_id":"全部","class_no":"全部","orientation":"全部","course_id":"全部","teacher_status":"休息"},{"work_id":"WNCD028","classroom_id":"全部","class_no":"全部","orientation":"全部","course_id":"全部","teacher_status":"实训"},{"work_id":"WNCD030","classroom_id":"全部","class_no":"全部","orientation":"全部","course_id":"全部","teacher_status":"实训"},{"work_id":"WNCD051","classroom_id":"全部","class_no":"全部","orientation":"全部","course_id":"全部","teacher_status":"实训"},{"work_id":"WNCD046","classroom_id":"全部","class_no":"全部","orientation":"全部","course_id":"全部","teacher_status":"实训"},{"work_id":"WNCD060","classroom_id":"全部","class_no":"全部","orientation":"全部","course_id":"全部","teacher_status":"实训"},{"work_id":"WNCD067","classroom_id":"全部","class_no":"全部","orientation":"全部","course_id":"全部","teacher_status":"实训"}]',
            'startTime': '2018-10-25', 'endTime': '2018-11-11'}
        headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
        r = self.s.post(url, data=data, headers=headers)
        print(r.text)

    def course_modify(self):
        # 修改排课
        url = self.base_url + '/WoniuBoss2.5/student/saveModifyCourse'
        headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
        # 教室的id是cur.classroom_id, classroom_id
        data = 'cur.id=678&cur.classroom_id=8&cur.course_id=a.txt&cur.start_time=2018-08-09&cur.end_time=2018-10-10&teacherName=%E9%82%93%E4%B9%83%E6%96%87&cur.teacher_status=%E6%AD%A3%E5%B8%B8&orientation=%E5%85%AC%E5%85%B1&course_id=a.txt&class_no=WNCDC034&classroom_id=8'
        r = self.s.post(url, headers=headers, data=data)
        print(r.text)

    def stage_measurement(self):
        # 阶段测评
        url = self.base_url + '/WoniuBoss2.5/student/saveScore'
        data = {'pe.phase_exam_student_id': '1252', 'pe.phase': '公共基础阶段', 'pe.score': '99', 'status': 'a.txt',
                'pe.comment': 'test'}
        headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
        r = self.s.post(url, data=data, headers=headers)
        print(r.text)


if __name__ == '__main__':
    sm = StuManage()
    # sm.arrange_course()
    # sm.check_in_search()
    # sm.stage_measurement()
    sm.base_info_update()
    # sm.course_modify()
    # sm.photo_modify()
